<?php
/**
 * Created by PhpStorm.
 * User: Monkey
 * Date: 2021/10/13
 * Time: 11:27
 * Desc: Usdt
 */
declare (strict_types=1);

namespace app\api\controller;

use app\api\base\controller\Base;
use app\api\validate\UsdtValidate;

class Usdt extends Base
{
    /**
     * 详情
     */
    public function getDetail()
    {
        $bandCardInfo = \app\extend\model\Usdt::where([
            ['uid', '=', self::$UserInfo['id']]
        ])->find();

        return json(_S('获取成功', $bandCardInfo));
    }

    /**
     * 绑Usdt
     */
    public function bindUsdt()
    {
        if (request()->isPost()) {
            $validate = new UsdtValidate();
            $ret = $validate->scene('bindUsdt')->check(input());
            if (!$ret) {
                return json(_E($validate->getError()));
            }

            $address = input('address', '');
            $network = input('network', '');

            $usdtInfo = \app\extend\model\Usdt::where([
                ['uid', '=', self::$UserInfo['id']]
            ])->field('id')->find();
            if (!empty($usdtInfo)) {
                return json(_E('已经绑定过usdt'));
            }

            $result = \app\extend\model\Usdt::insert([
                'uid' => self::$UserInfo['id'],
                'address' => $address,
                'network' => $network,
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s')
            ]);
            if(!$result){
                return json(_E('绑定失败'));
            } else {
                return json(_S('绑定成功'));
            }
        }
    }
}
